(function () {
    //登录
    let btnLogin = document.querySelector('.btn-login');
    btnLogin && btnLogin.addEventListener('click', userLoginFn);

    function userLoginFn() {
        const tip1 = document.getElementsByClassName('tip1');
        const tip2 = document.getElementsByClassName('tip2');
        /** 获取输入框输入的信息 */
        const tel = document.querySelector('input[name="tel"]').value;
        const passwd = document.querySelector('input[name="passwd"]').value;
        /** 把数据提交给后端进行验证 */
        axios.post('/api/userlogin', {
            tel,
            passwd
        }).then(function (res) {
            console.log(res);
            if (res.data.code === 1) {
                sessionStorage.setItem('uid', res.data.uid)
                window.location.href = './index.html';
            } else if (res.data.code === -1) {
                tip1[0].innerHTML = res.data.msg;
            } else if (res.data.code === 0) {
                tip2[0].innerHTML = res.data.msg;
            }
        }).catch(function (error) {
            console.log(error);
        });
    }
}
)();
